$(document).ready(function(e) {
	var fwidth = $(window).width();
    //图片轮播
    var picsc = new ScrollPic();
    picsc.scrollContId = "ImgDiv"; //内容容器ID
    picsc.dotListId = "dot";//点列表ID
    picsc.dotOnClassName = "selected";//选中点的样式
    picsc.frameWidth = fwidth;
    picsc.pageWidth = 88;
    picsc.initialize(); //初始化
	
	$("#screen_1").click(function(){
	  alert("aaa");
	  window.location.href="huodongxiangqing.html";
	});
});

// JavaScript Document
function addTimeOptionDivCss()
{
	var detailListDiv=$(".timeLineOption .detailList .detailOption");
	$.each(detailListDiv,function(i,items){
		if(i==detailListDiv.length-1){
			$(items).addClass("lastListOption");
		}else{
			$(items).addClass("listOption");
		}
	});
}

	
	
/*初始化我的佣金*/
function initMyCommission(){
	var contentURl1=jsonserver+"home_CountCommissionMonth.do";
	var contentParamsStr1="natureid="+fid+"&Ukey="+ukey;
	$.ajax({
			url:contentURl1+"?callback=?",//获取JSON
			data:contentParamsStr1,
			dataType:"jsonp",
			success:function(json){
				if(json[0].result==1){	
					$("#curMonth").text(json[1].ONTIME.substring(5,7)*1+"月");
					$("#showMoney").text(json[1].TOTAL);
					$("#moneyDesc").text(json[0].info);
				}
			},
			error:function(){
				alert("报错了");
			}
			
		})
}
/*初始化时间轴*/
function initContent(){
	//初始化我的佣金
	
	var contentURl2=jsonserver+"home_timeOnline.do";
	var contentParamsStr2="natureid="+fid+"&Ukey="+ukey;
	$.ajax({
			url:contentURl2+"?callback=?",//获取JSON
			data:contentParamsStr2,
			dataType:"jsonp",
			success:function(json){
				
				if(json[0].result==1){	
					$(".timeLine").children().remove();
					var resultArray=json[1];
					//alert(resultArray.length);
					$.each(resultArray,function(i,items){
						
						var optionDiv=$("<div/>").addClass("timeLineOption");
						//if(items.BANLI!=0 || items.PAISONG!=0 || items.JIEGUO!=0 || items.FANYONG!=0){
							if(i==0){
								var recDesc="";
								if(items.BANLI==0&&items.PAISONG==0&&items.JIEGUO==0&&items.FANYONG==0){
									recDesc='<div style=" color:#0066CC; text-align:center;" class="listOption">您今天没有办理推荐业务信息</div>';
								}
								var todayStr='<table width="100%">'+
												'<tr>'+
													'<td class="listLogo"><img src="images/index/index_time1.png"/></td>'+
													'<td>'+
													 '<div class="detailList">'+
														  '<div class="listTitle">'+getDayText(i)+'&nbsp; &nbsp;&nbsp;<span>'+items.DTD+'</span></div>'+ 
														recDesc+
														'<div style=" text-align:center;" class="listOption"><div class="recBtn"  style="line-height:50px; height:50px; width:260px; margin:15px auto;" onClick="requestRec(\'index\')">点这里推荐一下!</div></div>';
								  if(items.BANLI!=0){
									  todayStr+='<div style="background:url(\'images/index/index_procing.png\') no-repeat"  class="detailOption" onClick="requestDetail(1)"><div style="margin-left:130px;float:left">正在办理&nbsp;<label id="BANLI">'+items.BANLI+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.PAISONG!=0){
									  todayStr+='<div style="background:url(\'images/index/index_sending.png\') no-repeat"  class="detailOption" onClick="requestDetail(2)"><div style="margin-left:130px;float:left">正在派送&nbsp;<label id="PAISONG">'+items.PAISONG+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.JIEGUO!=0){
									  todayStr+='<div style="background:url(\'images/index/index_recresult.png\') no-repeat"  class="detailOption" onClick="requestDetail(3)"><div style="margin-left:130px;float:left">推荐结果&nbsp;<label id="JIEGUO">'+items.JIEGUO+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.FANYONG!=0){
									 todayStr+='<div style="background:url(\'images/index/index_back.png\') no-repeat"  class="detailOption" onClick="requestDetail(4)"><div style="margin-left:130px;float:left">返佣消息&nbsp;<label id="FANYONG">'+items.FANYONG+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								todayStr+='</div></td></tr></table>';
								optionDiv.append(todayStr);	
							}else if(i==resultArray.length-1){
								var todayStr='<table width="100%">'+
												'<tr>'+
													'<td class="listLogo"><img src="images/index/index_time2.png"/></td>'+
													'<td>'+
													 '<div class="detailList">'+
														  '<div class="listTitle"><span style=" font-size:42px;">'+items.DTD+'开始</span></div>';
								  if(items.BANLI!=0){
									  todayStr+='<div style="background:url(\'images/index/index_procing.png\') no-repeat"  class="detailOption" onClick="requestDetail(1)"><div style="margin-left:130px;float:left">正在办理&nbsp;<label id="BANLI">'+items.BANLI+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.PAISONG!=0){
									  todayStr+='<div style="background:url(\'images/index/index_sending.png\') no-repeat"  class="detailOption" onClick="requestDetail(2)"><div style="margin-left:130px;float:left">正在派送&nbsp;<label id="PAISONG">'+items.PAISONG+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.JIEGUO!=0){
									  todayStr+='<div style="background:url(\'images/index/index_recresult.png\') no-repeat"  class="detailOption" onClick="requestDetail(3)"><div style="margin-left:130px;float:left">推荐结果&nbsp;<label id="JIEGUO">'+items.JIEGUO+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.FANYONG!=0){
									 todayStr+='<div style="background:url(\'images/index/index_back.png\') no-repeat"  class="detailOption" onClick="requestDetail(4)"><div style="margin-left:130px;float:left">返佣消息&nbsp;<label id="FANYONG">'+items.FANYONG+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								todayStr+='</div></td></tr></table><br><br><br><br>';
								optionDiv.append(todayStr);	
								
							}else{
								var todayStr='<table width="100%">'+
												'<tr>'+
													'<td class="listLogo"><img src="images/index/index_time2.png"/></td>'+
													'<td>'+
													 '<div class="detailList">'+
														  '<div class="listTitle">'+getDayText(i)+'&nbsp; &nbsp;<span>'+items.DTD+'</span></div>';
								  if(items.BANLI!=0){
									  todayStr+='<div style="background:url(\'images/index/index_procing.png\') no-repeat"  class="detailOption" onClick="requestDetail(1)"><div style="margin-left:130px;float:left">正在办理&nbsp;<label id="BANLI">'+items.BANLI+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.PAISONG!=0){
									  todayStr+='<div style="background:url(\'images/index/index_sending.png\') no-repeat"  class="detailOption" onClick="requestDetail(2)"><div style="margin-left:130px;float:left">正在派送&nbsp;<label id="PAISONG">'+items.PAISONG+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.JIEGUO!=0){
									  todayStr+='<div style="background:url(\'images/index/index_recresult.png\') no-repeat"  class="detailOption" onClick="requestDetail(3)"><div style="margin-left:130px;float:left">推荐结果&nbsp;<label id="JIEGUO">'+items.JIEGUO+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								  if(items.FANYONG!=0){
									 todayStr+='<div style="background:url(\'images/index/index_back.png\') no-repeat"  class="detailOption" onClick="requestDetail(4)"><div style="margin-left:130px;float:left">返佣消息&nbsp;<label id="FANYONG">'+items.FANYONG+'</label>&nbsp;单</div><div style="margin-right:100px;height:88px;width:60px;float:right;background:url(\'images/wo_list_jiantou.png\') right center no-repeat"></div></div>';
								  }
								todayStr+='</div></td></tr></table>';
								optionDiv.append(todayStr);	
							}
						//}
						optionDiv.appendTo($(".timeLine"));	
					});
					addTimeOptionDivCss();
					
				}
				
			},
			error:function(){
				alert("报错了");
			}
			
		})

	

}
function initMsg(){
	//初始化消息个数
	$.ajax({
			url:jsonserver+"msg_unreadMessageNum.do?callback=?",//获取JSON
			data:"MSG_NATURE_FID="+fid,
			dataType:"jsonp",
			success:function(json)
			{
				var resultCode=json[0].result;
				if(resultCode==1){
					if(json[1].unreadMessageNum*1==0){
						$("#messageDiv").hide();
						$("#msgCount").hide();
						$("#messageLi").remove();
					}else{
						$("#msgCount").css("background","url(images/index/msg/msg_count.png) no-repeat");
						$("#msgCount").text(json[1].unreadMessageNum);
						$("#msgDetail").text(json[1].unreadMessageNum);
					}
				}
			},
			error:function(){
				alert("出错了!");
			}
			
		});	
	//初始化消息列表
	//initMsgList();
		
}
function initMsgList(){
	$.ajax({
			url:jsonserver+"msg_getMsgDayList.do?callback=?",//获取JSON
			data:"MSG_NATURE_FID="+fid+"&pageSize=10&MSG_IS_READED=0&setR=0&ukey="+ukey,
			dataType:"jsonp",
			success:function(json)
			{
				$("#msgList .menuOption").children().remove();
				var resultCode=json[0].result;
				if(resultCode==1){
					var datas=json[1].data;
					//alert(datas.length);
					var optionDiv="";
					$.each(datas,function(i,items){
						//alert(1);
						
						optionDiv+='<div style="font-size:28px;" onClick="requestDingxq(\''+items.MSG_ORDER_FID+'\')"><span style="margin-left:5%;">'+items.CUI_NAME+'</span><span style="margin-left:20px; font-size:22px;">'+items.CUI_CONTACTTEL+'</span><span style="margin-left:20px; font-size:20px; color:#ccc;">'+items.MSG_TYPE_NAME+'</span><img src="images/wo_list_jiantou.png" style=" float:right; margin-top:31px; margin-right:10%;"/></div>';
					});
					//alert(optionDiv);
					$("#messageDiv .menuOption").html(optionDiv);
					
				}
			},
			error:function(){
				alert("出错了!");
			}
			
		});	
}
function initU48(){
	$.ajax({
				type: "get",
				url:jsonserver+"other_queryRegionList.do?",//获取JSON
				data:"callback=?&NP_INFO_ID="+fid,
				dataType:"jsonp",
				success:function(json){
					if(json[0].result==1){
						if(json[1].length>0){
							//地域进行遍历
							var _html='';
							for(i=0;i<json[1].length;i++){		
								var obj = json[1][i];
								if(i==0){
									_html +='<option  selected="selected"  value="'+obj.AREA_ID+'">'+obj.NAME+'</option>';
									}else{
										_html +='<option   value="'+obj.AREA_ID+'">'+obj.NAME+'</option>';
									}
							}
							$("#u48").append(_html);
						}
					}
				},
				error:function(){
				alert("出错了!");
				}
				
			});
}

function firstLoginInitData(){
	var date=new Date();
	var year=date.getFullYear();
	var month=date.getMonth()+1;
	var day=date.getDate();
	$.ajax({
				type: "get",
				url:jsonserver+"home_firsrLoginRecommendInfo.do?",//获取JSON
				data:"callback=?&NP_INFO_ID="+fid,
				dataType:"jsonp",
				success:function(json){
					var t=json[1];
					var optionDiv=$("<div/>").addClass("timeLineOption");
					var todayStr='<table width="100%">'+
									'<tr>'+
										'<td class="listLogo"><img src="images/index/index_time1.png"/></td>'+
										'<td>'+
										 '<div class="detailList">'+
											  '<div class="listTitle" style="font-size:42px;" >今天&nbsp; &nbsp;&nbsp;<span>'+year+'/'+month+'/'+day+'</span></div>'+ 
											'<div style=" color:#0066CC; text-align:center;" class="listOption">您今天没有办理推荐业务信息</div>'+
											'<div style=" text-align:center;" class="listOption"><div class="recBtn"  style="line-height:50px; height:50px; width:260px; margin:15px auto; " onClick="requestRec(\'index\')">点这里推荐一下!</div></div>'+
									  '</div>'+
									'</td></tr></table><br><br>';
					 todayStr+='<table width="100%">'+
								'<tr>'+
									'<td class="listLogo"></td>'+
									'<td>'+
									 '<div class="detailList">'+
											'<div class="listOption" style="height:auto;">'+
												'<li>已经有<span>9527</span>人推荐了联通业务!</li>'+
												'<li>已经有<span>6580</span>人拿到了佣金!</li>'+
												'<li>推荐好友,办联通业务,赚佣金!</li>'+
												'<li>还在等待吗?最火的业务推荐一把!<li>'+
											'</div>';
					//alert(json[2][0].PARENTID);
					$.each(json[2],function(i,items){
						//alert(i+"=="+items.PARENTNAME);
						todayStr+='<div class="listOption" onClick="requestRec2Page(\''+items.PARENTID+'\',\''+items.PARENTNAME+'\')" style="line-height:60px;"><img src="images/index/r.png" class="rc"/><span class="text1">'+items.REOMMENDNAME+'<span><img src="images/wo_list_jiantou.png" class="rc1"/></div>';
					});				
					todayStr+='</td></tr><tr><td class="listLogo"></td><td><p onClick="requestRec(\'index\')" style="text-align:center;color:#0066CC;font-size:32px;">-----------更多推荐-----------</p></td></tr></table>';
					optionDiv.append(todayStr);
				    optionDiv.appendTo($(".timeLine"));	
				    addTimeOptionDivCss();
				},
				error:function(){
					alert("出错了!");
				}
				
			});
}
function okBtnClick(){
	 		var newpassword = base64encode($('#password').val());
			 var repassword = base64encode($('#repassword').val());
			 if(email_test($('#email').val())!=0)
			  {
			    alert("Email格式不正确!");
			    return "";
			  }
			  if(newpassword.length<6)
			  {
				 jAlert("密码长度小于六位!",'注销',function(e){});
			    return "";
			  }
			var pp = $('#password').val();
			if(pp==""||$('#email').val()==""){
				alert("你输入的为空！");
			}else{
				 if(newpassword==repassword){
					 $.ajax({
							type: "get",
							url:jsonserver+"login_setNewPassword.do?",//获取JSON
							data:"callback=?&NP_INFO_ID="+fid+"&Ukey="+ukey+"&newPass="+newpassword+"&newPassSure="+repassword+""
							+"&NP_EMAIL="+$('#email').val()+"&NP_AREA_CODE="+$('#u48').val()+"",
							dataType:"jsonp",
							success:function(json){
								if(json[0].result==1){
									$.cookie("password1",newpassword,{path:"/",expires:15});
								}
							},
							error:function(){
							alert("出错了!");
							}
							
						});
						$('.floatBoxBg').hide();
						$('.middle1').hide();
						localStorage.setItem(fid,"1");
				 }else{
					 alert('输入的密码不对');
				 }
			}

}


function resize(){

	setTimeout(function(){
		//loaded();
	},100);
}
function getDayText(i){
	var t="";
	switch(i){
		case 0:
		t="今天";
		break;
		case 1:
		t="昨天";
		break;
		case 2:
		t="前一周";
		break;
		case 3:
		t="前一月";
		break;
		case 4:
		t="前三月";
		break;
		case 5:
		t="历史";
		break;
	}
	return "<span style='font-size:42px;'>"+t+"</span>";
}
function requestRec2Page(busi_id,busi_name)
{
	window.location.href="business3G.html?busi_id="+busi_id+"&busi_name="+escape(busi_name);
}
function requestRec(op){
	
	
	window.location.href="businessRecommend.html?op="+op;
}
function requestDetail(tabIndex){
	window.location.href="detailQuery.html?requestPage=index&op=index&tabIndex="+tabIndex;
}